﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace NovelL
{
    public class GameFSM : MonoBehaviour
    {
        private GameState curState;

        public enum GameState
        {
            UIState, GameState, ExitState
        }
        // Start is called before the first frame update
        void Start()
        {
            curState = GameState.UIState;
            RecordManager.Instance.ReadSetting(); //初始化玩家设置
        }

        // Update is called once per frame
        void Update()
        {

        }

        public void ChangeState(GameState state)
        {
            if (state == curState)
            {
                return;
            }
            if (state == GameState.GameState)
            {
                if (curState == GameState.UIState)
                {
                    FromUIToGame();
                    curState = GameState.GameState;
                }

                else if (curState == GameState.ExitState)
                {
                    throw new Exception("从退出到游戏是不允许的状态转换");
                }
            }

            else if (state == GameState.UIState)
            {
                if (curState == GameState.GameState)
                {
                    FromGameToUI();
                    curState = GameState.UIState;
                }

                else
                {
                    throw new Exception("从退出到UI是不允许的状态转换");
                }
            }

            else if (state == GameState.ExitState)
            {
                if (curState == GameState.UIState)
                {
                    FromUIToExit();
                    curState = GameState.ExitState;
                }

                else
                {
                    throw new Exception("从游戏到退出是不允许的状态转换");
                }
            }

            else
            {
                Debug.LogError("状态机异常");
            }
        }

        private void FromUIToExit()
        {
            throw new NotImplementedException();

        }

        private void FromGameToUI()
        {
            throw new NotImplementedException();
        }

        private void FromUIToGame()
        {
            throw new NotImplementedException();
        }
    }
}

